/*
 * QTXpost - a Qt-based blog client.
 * Copyright (C) 2010 Helen Sommer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program (in COPYING); if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA  02111-1307  USA
 *
 * The project is hosted on http://code.google.com/p/qtxpost
 */

#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

#include <QtCore>
#include <QtGui>

#include "ui_MainWindow.h"
#include "ui_ImageEntry.h"
// #include "ui_LinkEntry.h"
#include "ServerConfig.h"
#include "Server.h"
#include "PostProgress.h"
#include "Preview.h"
#include "SelectPost.h"
#include "FriendsManager.h"

class MainWindow : public QMainWindow, private Ui::MainWindow
{
  Q_OBJECT

    public:
  MainWindow(QWidget *parent = 0);

  ServerConfig *serverConfig;
  QList<Server *> servers;
  QHash<QString, QList <int> > moods;
  QButtonGroup *selectedGroup;
  PostProgress *postProgress;
  Preview *preview;
  SelectPost *selectPost;
  FriendsManager *friendsManager;
  int editedServer;
  bool isEdit;
  bool isLastPost;
  QString lastSubject;
  QDateTime lastDate;

  void addServer(QString username, QString password, QString sitename, QString server, int serverType);
  void reorderServers();
  void updateMoods();
  void displayMoods();
  void updateIcons(int id, QString keyword);
  void setLastPost(QString url, QString subject, QString eventtime, 
                   QString security, qlonglong allowmask, QString event,
                   QString current_mood, QString taglist,
                   QString current_music, QString current_location);
  QString getSubject();
  QString getSecurity();
  QString getMusic();
  QString getLocation();
  QString getTags();
  QString getMood();
  QString getDate();
  QByteArray getText();
  bool isHidden();
  void editPost(Server *server);
  void findItems();

 private:
  QToolBar *toolBar;
  QHBoxLayout *serversLayout;
  QString openFileDirectory;
  QString saveFileDirectory;
  QShortcut *shortcutQuit;

  bool isValidBackdate();
  void fixServersPosition();

  private slots:
  void post();
  void openPreview();
  void openConfig();
  void openServerConfig();
  void toggleBackdated(int);
  void updateProperties();
  void editLastPost();
  void validateLastPost();
  void about();
  void wordCount();
  void selectEditPost();
  void openFile();
  void saveFile();
  void detectMusic();
  void insertBold();
  void insertItalic();
  void insertUnderline();
  void insertOverstrike();
  void insertAddress();
  void insertImage();
  void insertCut();
  void insertUser();
  void insertCommunity();
  void openFriendsManager();
};

#endif
